//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CSimpleMesh10.cpp>
///	@path	~/src/graphics/dx10/
///	@date	2009/01/10
///	@desc	.

#include "config/config.h"

#include "graphics/dx10/CSimpleMesh10.h"

namespace xeres {

	IMPL_IOBJECT_CLASS( CSimpleMesh10 );
	
	// CSimpleMesh10
	CSimpleMesh10::CSimpleMesh10( TopologyType type , RefWeak<IVertexLayout> layout , RefWeak<IVertexBuffer> vertex , RefWeak<IVertexIndex> index )
		: m_type( d3d_topology_type10( type ) )
		, m_layout( layout )
		, m_vertex( vertex )
		, m_index( index )
	{
		size_t count = 0;
		if( m_index.IsValid() )
			count = m_index->GetCount();
		m_prim = d3d_prim_count( type , vertex->GetCount() , count );
	}
	// ~CSimpleMesh10
	CSimpleMesh10::~CSimpleMesh10( void )
	{
	}
	// OnLostDevice
	bool CSimpleMesh10::OnLostDevice( void )
	{
		return true;
	}
	// OnResetDevice
	bool CSimpleMesh10::OnResetDevice( RefWeak<IDevice> device )
	{
		return true;
	}
	// GetLayout
	RefWeak<IVertexLayout> CSimpleMesh10::GetLayout( void )
	{
		return m_layout;
	}
	// EstablishBuffer
	void CSimpleMesh10::EstablishBuffer( RenderContext& rc )
	{
		m_layout->ApplyLayout( rc );
		m_vertex->ApplyStream( rc , 0 );
		if( m_index.IsValid() )
			m_index->ApplyIndex( rc );
	}
	// Draw
	void CSimpleMesh10::Draw( RenderContext& rc )
	{
		if( m_index.IsValid() )
		{
			rc.GetDX10()->DrawIndexed( m_index->GetCount() , 0 , 0 );
		}
		else
		{
			rc.GetDX10()->Draw( m_vertex->GetCount() , 0 );
		}
	}
	// ClearBuffer
	void CSimpleMesh10::ClearBuffer( RenderContext& rc )
	{
	}
	// GetSlotCount
	size_t CSimpleMesh10::GetSlotCount( void )
	{
		return 0;
	}
	// GetVertex
	RefWeak<IVertexBuffer> CSimpleMesh10::GetVertex( size_t slot )
	{
		XS_ASSERT( slot == 0 );
		return m_vertex;
	}
	// GetIndex
	RefWeak<IVertexIndex> CSimpleMesh10::GetIndex( void )
	{
		return m_index;
	}
	
} // namespace xeres
